<%-- 
    Document   : replacementdb
    Created on : Jan 14, 2013, 9:01:01 PM
    Author     : Bittuji
--%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.util.Date"%>
<%@include  file="db.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        
        String bno = request.getParameter("bno");
        String ptid = request.getParameter("ptid");
        
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        Date rpdate = format.parse(request.getParameter("rpdate"));
        java.sql.Date rpsqlDate = new java.sql.Date(rpdate.getTime());
        
        
        SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy");
        Date rtdate = format1.parse(request.getParameter("rtdate"));
        java.sql.Date rtsqlDate = new java.sql.Date(rtdate.getTime());
        
        
        String[] status = request.getParameterValues("status");
        String remark = request.getParameter("remark");
        String[] action = request.getParameterValues("rtype");
        
        for(int i=0;i<status.length;i++)
        {
        for(int j=0;j<action.length;j++)
        {               
        
        String sql = "INSERT INTO `replacement`(`bill_no`, `product_id`, `rep_date`, `ret_date`, `status`, `remarks`, `action`) VALUES (?,?,?,?,?,?,?)";
           
        PreparedStatement pstmt = con.prepareStatement(sql);
        
        pstmt.setString(1, bno);
        pstmt.setString(2, ptid);
        pstmt.setDate(3, rpsqlDate);
        pstmt.setDate(4, rtsqlDate);
        pstmt.setString(5, status[i]);
        pstmt.setString(6, remark);
        pstmt.setString(7, action[j]);
        
        int r = pstmt.executeUpdate();
        
        response.sendRedirect("replacement.jsp");
        
        }
        }
        
        
        
        %>
    </body>
</html>
